<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<script LANGUAGE="javascript">
function redirectPageComplete()
{	
	alert("บันทึกคำถามสำเร็จ");
	location = "../../faqs.php";
}

function redirectPageIncomplete()
{
	alert("เกิดข้อผิดพลาดในการเพิ่มข้อมูล");
	location = "../../faqs.php";
}

function redirectPageIsnull()
{
	alert("ข้อมูลบางส่วนยังเป็น่ค่าว่าง กรุณาลงใหม่อีกครั้ง");
	location = "../../faqs.php";
	
}
<?php
include '../../../inc/reuse/dbconfig.php';

$id = $_POST['faqs_id'];
$faqs_title = $_POST['faqs_title'];
$faqs_answer = $_POST['faqs_answer'];
$modifier = $_SESSION['uid'];
$modified_datetime = date("YmdHis"); //เก็บวันเดือนปีและเวลาด้วย function date
if(isset($faqs_title,$faqs_answer) && $id != ""){
	$sql = "UPDATE faqs
			SET faqs_title = '$faqs_title',
			faqs_answer = '$faqs_answer',			
			modified_master_id = '$modifier',
			modified_date_time = '$modified_datetime' 
			WHERE faqs_id= $id";
	if(mysql_query($sql)){
		echo "redirectPageComplete();";
	}else{
		echo "redirectPageIncomplete();";
	}
}
else
{
	$sql = "INSERT INTO faqs (faqs_id,faqs_title,faqs_answer,inserted_master_id,inserted_date_time,modified_master_id,modified_date_time)
	VALUES (null,'$faqs_title', '$faqs_answer', '$modifier', '$modified_datetime', '$modifier', '$modified_datetime')";
	if(mysql_query($sql)){
		echo "redirectPageComplete();";
	}else{
		echo "redirectPageIncomplete();";
	}	
}
mysql_close();
?>
</script>
</body>
</html>
